Manage cost centers and limits

BudgetManager

Manage cost centers and limits.

class yandex_b2b_go.budget.BudgetManager(client: Client)

Attributes

BudgetLimitManager

Manager to control limits.

class yandex_b2b_go.budget.BudgetLimitManager(client: Client)

Methods

  • list — returns a list of existing limits.
  • update — changes an employee's personal limit.

List

Returns a list of existing limits.

async def list(
    service: Optional[Service] = None, 
    department_id: Optional[str] = None, 
    limit: Optional[int] = None, 
    offset: Optional[int] = None,
    search: Optional[str] = None, 
    sorting_order: Optional[SortingOrder] = None, 
    sorting_field: Optional[str] = None
) -> BudgetLimitListResponse

Parameters

  • service — a list of limits for a specific service.
  • department_id — a list of limits for a specific department.
  • limit — number of records to display. If this parameter is not specified, information about the first 100 records is returned.
  • offset — number of skipped records. If this parameter is missing, information is returned starting from the first record.
  • search — additional limit filter (by full match in the title field).
  • sorting_order — sorting direction.
  • sorting_field — the field to sort by.

If the request is successful, the method returns the BudgetLimitListResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import BudgetManager
from yandex_b2b_go import typing, errors

TOKEN = '<your token>'

async def main():
client = Client(token=TOKEN)
budget_manager = BudgetManager(client=client)
try:
    limits_list = await budget_manager.limit.list(
        service=typing.Service.taxi,
        limit=5,
    )
    ...
except errors.ValidationError as e:
    return str(e.args)
except errors.ApiError as e:
    return e

asyncio.run(main())

Update

Change an employee's personal limit.

async def update(
    user_id: str, 
    budget_limit: Union[BudgetLimitTaxiRequest, BudgetLimitEatsRequest, BudgetLimitGroceryRequest, 
    BudgetLimitTankerRequest, BudgetLimitDriveRequest, BudgetLimitCargoRequest, BudgetLimitTravelRequest]
) -> BudgetLimitUpdateResponse

Parameters

If the request is successful, the method returns the BudgetLimitUpdateResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import BudgetManager
from yandex_b2b_go import typing, errors

TOKEN = '<your token>'

async def main():
    client = Client(token=TOKEN)
    budget_manager = BudgetManager(client=client)
    try:
        budget_limit = typing.BudgetLimitTaxiRequest(
            title='limit name',
            client_id='client ID',
            service=typing.Service.taxi,
            categories=['child_tariff', 'cargo', 'business', 'courier', 'express'],
            limits=typing.Limits(
                orders_cost=typing.Measure(
                    value=818181,
                    period=typing.MeasurePeriod.month,
                ),
                orders_amount=typing.Measure(
                    value=2,
                    period=typing.MeasurePeriod.day,
                )
            )
        )
        response_update = await budget_manager.limit.update(
            user_id='f1387…5e179',
            budget_limit=budget_limit
        )
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())

BudgetCostCenterManager

Manage cost centers.

class yandex_b2b_go.budget.BudgetCostCenterManager(client: Client)

Method

  • list — returns a list of existing cost centers.

List

Returns a list of existing cost centers.

async def list(
    limit: Optional[int] = None, 
    offset: Optional[int] = None
) -> BudgetCostCenterListResponse

Parameters

  • limit — number of records to display. If this parameter is not specified, information about the first 100 records is returned.
  • offset — number of skipped records. If this parameter is missing, information is returned starting from the first record.

If the request is successful, the method returns the BudgetCostCenterListResponse class.

If the parameters are incorrect, the method returns the ValidationError error.

If the response code is not 200, an error is returned: ApiError.

Request example

import asyncio

from yandex_b2b_go import Client
from yandex_b2b_go import BudgetManager
from yandex_b2b_go import typing, errors

TOKEN = '<your token>'


async def main():
    client = Client(token=TOKEN)
    budget_manager = BudgetManager(client=client)
    try:
        cost_centers = await budget_manager.cost_center.list(limit=5, offset=10)
        ...
    except errors.ValidationError as e:
        return str(e.args)
    except errors.ApiError as e:
        return e

asyncio.run(main())